package com.bilibili.juc.syncup;

import org.openjdk.jol.info.ClassLayout;

/**
 * @author zuife
 * @description
 * @since 2024-05-12 16:09:51
 */
public class SynchronizedUpDemo {
    public static void main(String[] args) {
       // noLock();
        //偏向锁
        //pianxiangLock();
        //轻量锁
        //qiliangLock();

        Object o = new Object();
        new Thread(() -> {
            synchronized (o) {
                System.out.println(ClassLayout.parseInstance(o).toPrintable());
            }
        }, "t1").start();
        new Thread(() -> {
            synchronized (o) {
                System.out.println(ClassLayout.parseInstance(o).toPrintable());
            }
        }, "t2").start();
        new Thread(() -> {
            synchronized (o) {
                System.out.println(ClassLayout.parseInstance(o).toPrintable());
            }
        }, "t3").start();
    }

    private static void qiliangLock() {
        Object o = new Object();
        new Thread(() -> {
             synchronized (o) {
                 System.out.println(ClassLayout.parseInstance(o).toPrintable());
             }
        }, "t1").start();
    }

    private static void pianxiangLock() {
        qiliangLock();
    }


    private static void noLock() {
        Object o = new Object();
//0000001010010101110010110100101
//0000001010010101110010110100101
        System.out.println("10进制：" + o.hashCode());
        System.out.println("16进制：" + Integer.toHexString(o.hashCode()));
        System.out.println("2进制：" + Integer.toBinaryString(o.hashCode()));
        System.out.println(ClassLayout.parseInstance(o).toPrintable());
    }
}
